package LeetCode_Section;

//链表中倒数第k个结点
public class FindLinked_Bottom_K {


    public class ListNode {
        int val;
        ListNode next = null;

        ListNode(int val) {
            this.val = val;
        }
    }
    public class Solution {
        public ListNode FindKthToTail(ListNode head,int k) {
            ListNode cur = head;
            int count = 0;
            while (cur != null) {
                ++count;
                cur = cur.next;
            }
            if (head == null || k < 0 || k > count) {
                return null;
            }

            cur = head;
            int val = count - k;
            while (val != 0) {
                --val;
                cur = cur.next;
            }
            return cur;
        }
    }

}
